package com.niiwoo.civet.trade.service.dubbo.credit;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONObject;
import com.niiwoo.civet.trade.constant.DatePatternConstant;
import com.niiwoo.civet.trade.dao.entity.CreditorSaleDetail;
import com.niiwoo.civet.trade.dao.entity.CreditorSelling;
import com.niiwoo.civet.trade.dao.entity.InvestStdConfig;
import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.dao.mapper.*;
import com.niiwoo.civet.trade.dto.CreditorSaleOrderRateAreaDTO;
import com.niiwoo.civet.trade.dto.common.LinkAgeConfigDTO;
import com.niiwoo.civet.trade.dto.request.creditor.CreditorAgreementUrlRequestDTO;
import com.niiwoo.civet.trade.dto.request.creditor.CreditorSalePageRequestDTO;
import com.niiwoo.civet.trade.dto.response.RelationInvestStdConfigDTO;
import com.niiwoo.civet.trade.dto.response.RelationInvestStdConfigItemDTO;
import com.niiwoo.civet.trade.dto.response.creditor.CreditorAgreementUrlResponseDTO;
import com.niiwoo.civet.trade.dto.response.creditor.CreditorSaleDetailResponseDTO;
import com.niiwoo.civet.trade.dto.response.creditor.CreditorSalePageResponseDTO;
import com.niiwoo.civet.trade.dto.response.creditor.TradableInvestOrderStatDTO;
import com.niiwoo.civet.trade.enums.InvestStdConfigTypeEnum;
import com.niiwoo.civet.trade.enums.InvestStdProductTypeEnum;
import com.niiwoo.civet.trade.enums.TradeConfigEnum;
import com.niiwoo.civet.trade.enums.creditorSale.SaleDetailStatusEnum;
import com.niiwoo.civet.trade.service.creditor.CreditorRightsDubboService;
import com.niiwoo.civet.trade.service.local.configure.InvestStdConfigLocalService;
import com.niiwoo.civet.trade.service.local.configure.TradeConfigLocalService;
import com.niiwoo.civet.trade.service.local.credit.CreditorSellingLocalService;
import com.niiwoo.civet.trade.service.local.creditor.CreditorRateConfigService;
import com.niiwoo.civet.trade.service.local.creditor.TradableInvestOrderService;
import com.niiwoo.civet.trade.utils.RepaymentUtil;
import com.niiwoo.civet.user.dto.response.UserBasicInfoDTO;
import com.niiwoo.civet.user.dto.response.UserBasicInfoResponseDTO;
import com.niiwoo.civet.user.service.OrganizationDubboService;
import com.niiwoo.civet.user.service.UserBasicInfoDubboService;
import com.niiwoo.tripod.base.utils.BigDecimals;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wping
 * @Description: 债权dubbo服务类
 * @date 2018/5/14 16:41
 */
@Slf4j
@Service(version = "1.0.0", validation = "true")
public class CreditorRightsDubboServiceImpl implements CreditorRightsDubboService {

    @Autowired
    private CreditorSaleDetailMapperExt creditorSaleDetailMapperExt;

    @Autowired
    private CreditorSellingMapperExt creditorSellingMapper;

    @Autowired
    private ProjectMapperExt projectMapperExt;

    @Autowired
    private InvestStdConfigMapperExt investStdConfigMapperExt;

    @Reference(version = "1.0.0")
    private OrganizationDubboService organizationDubboService;

    @Reference(version = "1.0.0")
    private UserBasicInfoDubboService userBasicInfoDubboService;

    @Value("${h5-creditor-project-presentation-url}")
    private String productPresentationUrl;
    @Value("${h5-creditor-common-problem-url}")
    private String commonProblemUrl;
    @Value("${h5-guarantee-model-url}")
    private String guaranteeModelH5Url;
    @Value("${h5-creditor-agreement-url}")
    private String creditorAgreementUrl;
    @Value("${h5-creditor-risk-agreement-url}")
    private String creditorRiskAgreementUrl;
    @Value("${h5-niiwoo-guarantee-model-url}")
    private String niiwooGuaranteeModelH5Url;
    @Autowired
    private CreditorRateConfigService creditorRateConfigService;
    @Autowired
    private TradableInvestOrderService tradableInvestOrderService;
    @Autowired
    private TradeConfigLocalService tradeConfigService;
    @Autowired
    private InvestorCreditorMapperExt investorCreditorMapperExt;
    @Autowired
    private InvestStdConfigLocalService investStdConfigLocalService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Autowired
    private CreditorSellingLocalService creditorSellingLocalService;

    @Override
    public List<LinkAgeConfigDTO> queryCreditorSaleSelector(Byte type) {

        List<LinkAgeConfigDTO> responseDTOList = new ArrayList<>();
        InvestStdProductTypeEnum investStdProductTypeEnum = InvestStdProductTypeEnum.enumOf(type);
        List<RelationInvestStdConfigDTO> list = investStdConfigLocalService.findRelationConfigByProductType(investStdProductTypeEnum.getValue());
        log.info("----queryCreditorSaleSelector 查询筛选条件记录为:" + JSONObject.toJSONString(list));
        if (!CollectionUtils.isEmpty(list)) {
            for (RelationInvestStdConfigDTO dto : list) {
                if (!CollectionUtils.isEmpty(dto.getItems())) {
                    List<RelationInvestStdConfigItemDTO> dtoList = dto.getItems();
                    LinkAgeConfigDTO responseDTO = new LinkAgeConfigDTO();
                    for (RelationInvestStdConfigItemDTO itemDTO : dtoList) {
                        Byte configType = itemDTO.getConfigType();
                        LinkAgeConfigDTO.Configure configure = new LinkAgeConfigDTO.Configure();
                        LinkAgeConfigDTO.Config config = new LinkAgeConfigDTO.Config();
                        if (configType.equals(InvestStdConfigTypeEnum.DEADLINE.getValue())) {
                            nomalValueObject(itemDTO, configure, config);
                            responseDTO.setPeriodType(configure);
                        } else if (configType.equals(InvestStdConfigTypeEnum.PRODUCT.getValue())) {
                            nomalValue(itemDTO, configure);
                            responseDTO.setProductType(configure);
                        } else if (configType.equals(InvestStdConfigTypeEnum.REPAYMENT.getValue())) {
                            nomalValue(itemDTO, configure);
                            responseDTO.setRepaymentType(configure);
                        } else if (configType.equals(InvestStdConfigTypeEnum.INTEREST_RATE.getValue())) {
                            nomalValueObject(itemDTO, configure, config);
                            responseDTO.setRateType(configure);
                        } else if (configType.equals(InvestStdConfigTypeEnum.INVESTABLE_AMOUNT.getValue())) {
                            nomalValueObject(itemDTO, configure, config);
                            responseDTO.setInvestableType(configure);
                        }
                    }
                    responseDTOList.add(responseDTO);
                }
            }
            List<InvestStdConfig> listAmounts = investStdConfigLocalService.selectByProductTypeAndConfigType(investStdProductTypeEnum.getValue(),InvestStdConfigTypeEnum.INVESTABLE_AMOUNT.getValue());
            if (!CollectionUtils.isEmpty(listAmounts)) {
                for (int i = 0; i < listAmounts.size(); i++) {
                    LinkAgeConfigDTO.Configure configure = new LinkAgeConfigDTO.Configure();
                    LinkAgeConfigDTO.Config config = new LinkAgeConfigDTO.Config();
                    nomalValueObject(getItemDTO(listAmounts.get(i)), configure, config);
                    LinkAgeConfigDTO dto = new LinkAgeConfigDTO();
                    dto.setFavorableType(responseDTOList.get(0).getFavorableType());
                    dto.setRateType(responseDTOList.get(0).getRateType());
                    dto.setRepaymentType(responseDTOList.get(0).getRepaymentType());
                    dto.setProductType(responseDTOList.get(0).getProductType());
                    dto.setPeriodType(responseDTOList.get(0).getPeriodType());
                    dto.setInvestableType(configure);
                    responseDTOList.add(dto);
                }
            }
        }
        return responseDTOList;
    }

    private RelationInvestStdConfigItemDTO getItemDTO(InvestStdConfig investStdConfig) {
        RelationInvestStdConfigItemDTO config = new RelationInvestStdConfigItemDTO();
        config.setMaxval(investStdConfig.getMaxval());
        config.setMaxvalCalSymbol(investStdConfig.getMaxvalCalSymbol());
        config.setMinval(investStdConfig.getMinval());
        config.setMinvalCalSymbol(investStdConfig.getMinvalCalSymbol());
        config.setSeq(investStdConfig.getSeq());
        config.setTermUnit(investStdConfig.getTermUnit());
        config.setTitle(investStdConfig.getTitle());
        return config;
    }

    private void nomalValueObject(RelationInvestStdConfigItemDTO itemDTO, LinkAgeConfigDTO.Configure configure, LinkAgeConfigDTO.Config config) {
        config.setMaxval(itemDTO.getMaxval());
        config.setMaxvalCalSymbol(itemDTO.getMaxvalCalSymbol());
        config.setMinval(itemDTO.getMinval());
        config.setMinvalCalSymbol(itemDTO.getMinvalCalSymbol());
        config.setSeq(itemDTO.getSeq());
        config.setTermUnit(itemDTO.getTermUnit());
        config.setTitle(itemDTO.getTitle());
        configure.setName(itemDTO.getTitle());
        configure.setSort(itemDTO.getSeq());
        configure.setValue(config);
    }

    private void nomalValue(RelationInvestStdConfigItemDTO itemDTO, LinkAgeConfigDTO.Configure configure) {
        configure.setName(itemDTO.getTitle());
        configure.setSort(itemDTO.getSeq());
        configure.setValue(itemDTO.getByteVal());
    }

    @Override
    public List<CreditorSalePageResponseDTO> getCreditorSalePage(CreditorSalePageRequestDTO requestDTO) {

        List<CreditorSalePageResponseDTO> result = new ArrayList<>();
        TradeConfigEnum key;
        key = TradeConfigEnum.TRANSFER_INVEST_SHOW_SIZE;

        String maxSizeAsString = redisTemplate.opsForValue().get(key.getConfigKey());
        if (StringUtils.isBlank(maxSizeAsString)) {
            maxSizeAsString = tradeConfigService.selectTradeConfigByEmun(key);
            if (StringUtils.isBlank(maxSizeAsString)) {
                return result;
            }
        }
        //最多展示条数 取配置
        if (requestDTO.getOffset() >= Integer.parseInt(maxSizeAsString)) {
            return result;
        }
        if (requestDTO.getOffset() + requestDTO.getPageSize() >= Integer.parseInt(maxSizeAsString)) {
            requestDTO.setPageSize(Integer.parseInt(maxSizeAsString) - requestDTO.getOffset());
        }
        List<CreditorSelling> list = creditorSellingMapper.selectPageByParams(requestDTO);
        if(CollectionUtils.isEmpty(list)){
           return result;
        }
        Set<String> stringList = list.stream().map(CreditorSelling::getUserId).collect(Collectors.toSet());
        List<UserBasicInfoDTO> dtoList = userBasicInfoDubboService.queryListByUserIdSet(stringList);
        for (CreditorSelling creditorSelling : list) {
            CreditorSaleDetail creditorSaleDetail = creditorSaleDetailMapperExt.selectByPrimaryKeyAndSaleUserId(creditorSelling.getCreditorSaleDetailId(), creditorSelling.getUserId());
            for (UserBasicInfoDTO userBasicInfoDTO : dtoList) {
                if(userBasicInfoDTO.getUserId().equals(creditorSelling.getUserId())){
                    creditorSelling.setNickName(userBasicInfoDTO.getNickName());
                    creditorSelling.setHeadImage(userBasicInfoDTO.getHeadImage());
                    break;
                }
            }
            CreditorSalePageResponseDTO dto = this.convertCreditorSalePageResponseDTO(creditorSelling, creditorSaleDetail);
            result.add(dto);
        }

        return result;
    }

    private CreditorSalePageResponseDTO convertCreditorSalePageResponseDTO(CreditorSelling creditorSelling, CreditorSaleDetail creditorSaleDetail) {
        reCalcAmount(creditorSaleDetail, creditorSelling);
        CreditorSalePageResponseDTO responseDTO = new CreditorSalePageResponseDTO();

        responseDTO.setCreditorSaleDetailId(creditorSelling.getCreditorSaleDetailId());
        responseDTO.setInvestOrderId(creditorSelling.getInvestOrderId());
        responseDTO.setProjectId(creditorSelling.getProjectId());
        responseDTO.setCreditorUserId(creditorSelling.getUserId());
        responseDTO.setCreditorHeadImage(creditorSelling.getHeadImage());
        responseDTO.setCreditorNickName(creditorSelling.getNickName());
        responseDTO.setCreditorGender(creditorSelling.getGender());
        responseDTO.setCreditorNiiwooScore(creditorSelling.getNiiwooScore());
        responseDTO.setBorrowRate(creditorSelling.getBorrowRate());
        responseDTO.setBorrowRateDesc(BigDecimals.formatBorrowRate(creditorSelling.getBorrowRate()));
        responseDTO.setDeadline(creditorSelling.getDeadline());
        responseDTO.setRemainingDeadlineMonth(creditorSelling.getRemainingDeadlineMonth());
        responseDTO.setRemainingDeadlineDay(creditorSelling.getStatus() == 1 ? changeDays(creditorSelling.getCreateTime(), creditorSelling.getRemainingDeadlineDay())
                : creditorSelling.getRemainingDeadlineDay());
        responseDTO.setEndDate(DateFormatUtils.format(creditorSelling.getEndDate(), DatePatternConstant.YYYY_MM_DD));
        responseDTO.setFavorableType(convertFavorableType(creditorSelling.getOffPercent()));
        responseDTO.setSaleAmount(creditorSelling.getSaleAmount());
        responseDTO.setAmount(creditorSelling.getShare());
        responseDTO.setOffPercent(creditorSelling.getOffPercent());
        responseDTO.setOffAmount(creditorSelling.getOffAmount());
        responseDTO.setInterest(creditorSelling.getInterest());
        responseDTO.setBorrowerType(creditorSelling.getBorrowerType());

        Date now = new Date();
        responseDTO.setCurrentTime(DateFormatUtils.format(now, DatePatternConstant.YYYY_MM_DD_HH_MM_SS));
        responseDTO.setExpireTime(DateFormatUtils.format(creditorSelling.getExpireTime(), DatePatternConstant.YYYY_MM_DD_HH_MM_SS));
        responseDTO.setCountDownTime(getDistanceSeconds(now, creditorSelling.getExpireTime()));

        responseDTO.setRepaymentType(creditorSelling.getRepaymentType());
        responseDTO.setStatus(creditorSelling.getStatus());


        return responseDTO;
    }

    public Integer changeDays(Date creatTime, Integer day) {
        return day - RepaymentUtil.getOverdueDay(creatTime, new Date());
    }

    public void reCalcAmount(CreditorSaleDetail detail, CreditorSelling creditorSelling) {
        if (!SaleDetailStatusEnum.SALE_SUCCESS.getValue().equals(detail.getStatus())) {
            tradableInvestOrderService.reCalcAmount(detail);
        }
        BigDecimal sellingInterest = detail.getSellingInterest();
        BigDecimal offAmount = detail.getOffAmount();
        if (creditorSelling != null) {
            creditorSelling.setSaleAmount(creditorSelling.getSaleAmount().add(sellingInterest));
            creditorSelling.setOffAmount(offAmount);
            creditorSelling.setInterest(creditorSelling.getInterest().subtract(sellingInterest).setScale(2, RoundingMode.HALF_EVEN));
        }
        detail.setSaleAmount(detail.getSaleAmount().add(sellingInterest));
        detail.setOffAmount(offAmount);
        detail.setInterest(detail.getInterest().subtract(sellingInterest).add(offAmount).setScale(2, RoundingMode.HALF_EVEN));
    }


    /**
     * 两个时间相差距离多少秒
     *
     * @param date1 时间参数 1 格式：1990-01-01 12:00:00
     * @param date2 时间参数 2 格式：2009-01-01 12:00:00
     * @return Integer 多少秒
     */
    private Integer getDistanceSeconds(Date date1, Date date2) {
        int seconds = (int) ((date2.getTime() - date1.getTime()) / (1000));
        return seconds;
    }

    // 优惠方式：1全价转让，2降价转让
    private Byte convertFavorableType(BigDecimal offPercent) {
        if (offPercent == null) {
            return 1;
        }

        if (offPercent.compareTo(new BigDecimal("0")) > 0) {
            return 2;
        }

        return 1;
    }

    @Override
    public CreditorSaleDetailResponseDTO getCreditorSaleDetail(Long creditorSaleDetailId, String saleUserId) {

        CreditorSaleDetailResponseDTO responseDTO = new CreditorSaleDetailResponseDTO();

        CreditorSaleDetail creditorSaleDetail = creditorSellingLocalService.getCreditorSaleDetail(creditorSaleDetailId,saleUserId);
        if (creditorSaleDetail != null) {
            responseDTO = convertCreditorSaleDetailResponseDTO(creditorSaleDetail);
            
            Project project = projectMapperExt.selectByPrimaryKey(creditorSaleDetail.getProjectId());
            if (project != null) responseDTO.setBorrowUserId(project.getBorrowUserId());
        }
        return responseDTO;
    }

    @Override
    public BigDecimal getRealTimeCreditorSaleDetailSaleAmount(Long creditorSaleDetailId, String saleUserId) {
        CreditorSaleDetail creditorSaleDetail = creditorSaleDetailMapperExt.selectByPrimaryKeyAndSaleUserId(creditorSaleDetailId, saleUserId);
        BigDecimal amount = BigDecimal.ZERO;
        if (creditorSaleDetail != null) {

            CreditorSaleDetail detail = new CreditorSaleDetail();
            BeanUtils.copyProperties(creditorSaleDetail, detail);
            tradableInvestOrderService.reCalcAmount(detail);

            amount = creditorSaleDetail.getSaleAmount().add(Objects.isNull(creditorSaleDetail.getSellingInterest()) ? BigDecimal.ZERO : creditorSaleDetail.getSellingInterest());
        }
        return amount;
    }


    @Override
    public TradableInvestOrderStatDTO getCreditorSaleOrderRateArea() {
        TradableInvestOrderStatDTO tradableInvestOrderStatDTO = new TradableInvestOrderStatDTO();
        CreditorSaleOrderRateAreaDTO rateConfig = creditorRateConfigService.getCreditorSaleOrderRateArea();
        if (rateConfig != null) {
            tradableInvestOrderStatDTO.setMinFeeRate(rateConfig.getMinRate());
        }
        return tradableInvestOrderStatDTO;
    }

    @Override
    public Integer queryCreditorIsInvest() {
        return creditorSellingMapper.selectCountByStatus();
    }

    @Override
    public List<CreditorAgreementUrlResponseDTO> queryCreditorAgreementUrl(CreditorAgreementUrlRequestDTO dto) {
        List<CreditorAgreementUrlResponseDTO> list = new ArrayList<>();
        CreditorAgreementUrlResponseDTO responseAgreementDTO = new CreditorAgreementUrlResponseDTO();
        responseAgreementDTO.setTitle("债权转让协议");
        CreditorAgreementUrlResponseDTO responseRiskAgreementDTO = new CreditorAgreementUrlResponseDTO();
        responseRiskAgreementDTO.setTitle("债权转让风险提示书");
        if (dto.getIsBatch() == 0) {
            responseAgreementDTO.setLink(creditorAgreementUrl + "?investOrderId=" + dto.getProjectInvestId() + "&saleAmount=" + dto.getSaleAmount());
            responseRiskAgreementDTO.setLink(creditorRiskAgreementUrl);
        } else {
            responseAgreementDTO.setLink(creditorAgreementUrl);
            responseRiskAgreementDTO.setLink(creditorRiskAgreementUrl);
        }
        list.add(responseAgreementDTO);
        list.add(responseRiskAgreementDTO);
        return list;
    }


    private CreditorSaleDetailResponseDTO convertCreditorSaleDetailResponseDTO(CreditorSaleDetail creditorSaleDetail) {
        UserBasicInfoResponseDTO userBasicInfoResponseDTO = userBasicInfoDubboService.selectUserBaseInfo(creditorSaleDetail.getUserId());
        reCalcAmount(creditorSaleDetail, null);
        CreditorSaleDetailResponseDTO responseDTO = new CreditorSaleDetailResponseDTO();
        responseDTO.setCreditorSaleDetailId(creditorSaleDetail.getId());
        responseDTO.setInvestOrderId(creditorSaleDetail.getInvestOrderId());
        responseDTO.setProjectId(creditorSaleDetail.getProjectId());
        responseDTO.setCreditorUserId(creditorSaleDetail.getUserId());
        responseDTO.setCreditorHeadImage(userBasicInfoResponseDTO == null ? creditorSaleDetail.getHeadImage() : userBasicInfoResponseDTO.getHeadImage());
        responseDTO.setCreditorNickName(userBasicInfoResponseDTO == null ? creditorSaleDetail.getNickName() : userBasicInfoResponseDTO.getNickName());
        responseDTO.setCreditorGender(creditorSaleDetail.getGender());
        responseDTO.setCreditorNiiwooScore(creditorSaleDetail.getNiiwooScore());
        responseDTO.setBorrowRate(creditorSaleDetail.getBorrowRate());
        responseDTO.setBorrowRateDesc(BigDecimals.formatBorrowRate(creditorSaleDetail.getBorrowRate()));
        responseDTO.setDeadline(creditorSaleDetail.getDeadline());
        responseDTO.setRemainingDeadlineMonth(creditorSaleDetail.getRemainingDeadlineMonth());
        responseDTO.setRemainingDeadlineDay(creditorSaleDetail.getStatus() == 1 ? changeDays(creditorSaleDetail.getCreateTime(), creditorSaleDetail.getRemainingDeadlineDay())
                : creditorSaleDetail.getRemainingDeadlineDay());
        responseDTO.setEndDate(DateFormatUtils.format(creditorSaleDetail.getEndDate(), DatePatternConstant.YYYY_MM_DD));
        responseDTO.setFavorableType(convertFavorableType(creditorSaleDetail.getOffPercent()));
        responseDTO.setSaleAmount(creditorSaleDetail.getSaleAmount());
        responseDTO.setAmount(creditorSaleDetail.getShare());
        responseDTO.setOffPercent(creditorSaleDetail.getOffPercent());
        responseDTO.setOffAmount(creditorSaleDetail.getOffAmount());
        responseDTO.setInterest(creditorSaleDetail.getInterest());
        responseDTO.setRealName(creditorSaleDetail.getRealName());
        responseDTO.setBorrowerType(creditorSaleDetail.getBorrowerType());


        Date now = new Date();
        responseDTO.setCurrentTime(DateFormatUtils.format(now, DatePatternConstant.YYYY_MM_DD_HH_MM_SS));
        responseDTO.setExpireTime(DateFormatUtils.format(creditorSaleDetail.getExpireTime(), DatePatternConstant.YYYY_MM_DD_HH_MM_SS));
        responseDTO.setCountDownTime(getDistanceSeconds(now, creditorSaleDetail.getExpireTime()));

        responseDTO.setRepaymentType(creditorSaleDetail.getRepaymentType());
        responseDTO.setStatus(creditorSaleDetail.getStatus());

        Project project = projectMapperExt.selectByPrimaryKey(creditorSaleDetail.getProjectId());
        if (project != null) {
            String loanUsage = "";
            if (StringUtils.isNotBlank(project.getTitle())) {
                loanUsage = "借款用途：".concat(project.getTitle().trim().replaceAll("借款用于", ""));
            }
            responseDTO.setLoanUsage(loanUsage);
            responseDTO.setProjectType(project.getType());
        }

        // TODO GWP url修改
        responseDTO.setCommonProblemUrl(commonProblemUrl);
        // TODO GWP url修改以及产品字段如何传送
        responseDTO.setProductPresentationUrl(productPresentationUrl);

        responseDTO.setCreditorRiskAgreementUrl(creditorRiskAgreementUrl + "?creditorSaleDetailId=" + creditorSaleDetail.getId() + "&transferUserId=");

        responseDTO.setCreditorAgreementUrl(creditorAgreementUrl + "?creditorSaleDetailId=" + creditorSaleDetail.getId() + "&transferUserId=");
        //查看是否可转让
        String hand = tradeConfigService.selectTradeConfigByEmun(TradeConfigEnum.DEBT_TRANSFER_TAG_PERIOD);
        log.info("债权转让详情读取配置信息:手持债权最少时间为{}", hand);
        responseDTO.setIstransfer(creditorSaleDetail.getRemainingDeadlineMonth() >= Integer.parseInt(hand) ? (byte) 1 : (byte) 0);
        // 担保方式H5页面
        String guaranteeModelH5Url = this.guaranteeModelH5Url + "?advanceOverdueDays=" + (project.getAdvanceOverdueDays() == null ? 0 : project.getAdvanceOverdueDays());
        responseDTO.setGuaranteeModelH5Url(guaranteeModelH5Url);

        return responseDTO;
    }

    //1-可转让，2-已售完，3-已结束(失败)
    /*private Byte transfer(Byte status) {
        if (SaleDetailStatusEnum.SELLING.getValue().equals(status)) {
            return (byte) 1;
        } else if (SaleDetailStatusEnum.SALE_SUCCESS.getValue().equals(status)) {
            return (byte) 3;
        } else if (SaleDetailStatusEnum.PRE_CREDIT_ASSIGNMENT_HANDING.getValue().equals(status) ||
                SaleDetailStatusEnum.CONFIRM_CREDIT_ASSIGNMENT_HANDING.getValue().equals(status) ) {
            return (byte) 2;
        } else {
            return (byte) 3;
        }

    }*/
}
